import Vue from 'vue'
import VueRouter from 'vue-router'

// 防止多次点击报错的代码 将初始方法去出来后加了.catch
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}

const Home = () => import('../views/home/home.vue')
const Catgory = () => import('../views/catgory/category.vue')
const Cart = () => import('../views/cart/cart.vue')
const User = () => import('../views/user/user.vue')



Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: 'home',
    component: Home
  },
  {
    path:'/home',
    component: Home
  },
  {
    path: '/catgory',
    component: Catgory
  },
  {
    path: '/cart',
    component: Cart
  },
  {
    path: '/profile',
    component: User
  },

]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
